package com.lanou.horo.zhuizhui.adapter;

import android.content.Context;
import android.graphics.Bitmap;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.android.volley.toolbox.ImageLoader;
import com.android.volley.toolbox.NetworkImageView;
import com.lanou.horo.zhuizhui.entity.CartoonMessageItems.ArticlesEntity;
import com.lanou.horo.zhuizhui.utility.imageLoader.AsyncImageLoader;
import com.lanou.horo.zhuizhui.R;
import com.lanou.horo.zhuizhui.utility.imageLoader.VolleySingleton;


import java.util.List;

/**
 * Created by dllo on 15/10/26.
 */
public class CartoonMessageAdapter extends
        RecyclerView.Adapter<CartoonMessageAdapter.CartoonMessageViewHolder> {
    private List<ArticlesEntity> articlesEntities;
    private Context context;
    private ImageLoader imageLoader;

    public List<ArticlesEntity> getArticlesEntities() {
        return articlesEntities;
    }

    public CartoonMessageAdapter(Context context) {
        this.context = context;
        imageLoader = VolleySingleton.getInstance().getImageLoader();
    }

    public void addArtList(List<ArticlesEntity> datas) {
        articlesEntities = datas;
        notifyDataSetChanged();
    }


    @Override
    public CartoonMessageViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        LayoutInflater inflater = LayoutInflater.from(parent.getContext());
        View view = inflater.inflate(R.layout.activity_cartoon_message_item, null);

        return new CartoonMessageViewHolder(view);
    }

    @Override
    public void onBindViewHolder(CartoonMessageViewHolder holder, int position) {
        if (articlesEntities != null && articlesEntities.size() > 0) {
            ArticlesEntity articlesEntity = articlesEntities.get(position);
            holder.textView.setText((String)articlesEntity.getTitle());
            holder.textViewZ.setText(articlesEntity.getUp_count());
            holder.textViewP.setText(articlesEntity.getComment_count());
            String url = articlesEntity.getCovers().get(0).getU();
            holder.imageView.setImageUrl(url,imageLoader);
        }
    }
    @Override
    public int getItemCount() {

        return articlesEntities != null && articlesEntities.size() > 0 ? articlesEntities.size() : 0;

    }


    public class CartoonMessageViewHolder extends RecyclerView.ViewHolder {
        private TextView textView , textViewZ, textViewP;
        private NetworkImageView imageView;


        public CartoonMessageViewHolder(View itemView) {
            super(itemView);
            textView = (TextView) itemView.findViewById(R.id.cartoonMessageItemTitle);
            imageView = (NetworkImageView) itemView.findViewById(R.id.cartoonMessageItemImg);
            textViewZ = (TextView) itemView.findViewById(R.id.TextViewForZan);
            textViewP = (TextView) itemView.findViewById(R.id.TextViewForPL);


        }
    }
}
